<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>查找数组[1,2,3,4,1,2,3,4,2,3,1,1,0]中所有值为1的项的下标 输出为新数组</title>
</head>

<body>
    <script>
        var Array = [1, 2, 3, 4, 1, 2, 3, 4, 2, 3, 1, 1, 0];
        var newArray = [];
        // var Index = 0;
        // for (var i = 0, len = Array.length; i < len; i++) {
        //     if(Array[i]===1){
        //         Index += "i";
        //     }else {
        //         newArray.push(Array[i]);
        //     }
        // }
        // console.log("所有值为1的项的下标为:"+Index);
        // console.log(newArray);
        for (var i = 0, len = Array.length; i < len; i++) {
            if (Array[i] === 1) {
                newArray.push(i);
            }
        }
        console.log("所有值为1的项的下标为:" + newArray);
    </script>
</body>

</html>